package C056;

import C017.main;

import java.io.*;
import java.util.Scanner;

/**
 * ClassName: C01
 * Package: C056
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/4/24 23:44
 * @Version 1.0
 * @Since 1.0
 */

// 并查集模版(牛客)
// 路径压缩 + 小挂大
// 测试链接 : https://www.nowcoder.com/practice/e7ed657974934a30b2010046536a5372
// 请同学们务必参考如下代码中关于输入、输出的处理
// 这是输入输出处理效率很高的写法
// 提交以下的code，提交时请把类名改成"Main"，可以直接通过
public class C01 {
    static int MAXLEN = 1000001;
    static int[] stack = new int[MAXLEN];
    static int[] father = new int[MAXLEN];
    static int[] sizes = new int[MAXLEN];
    static int size;

    static int n, m, op, x, y;
    public static void main(String[] args) throws IOException {
//        Scanner scan = new Scanner(System.in);
//        n = scan.nextInt();
//        m = scan.nextInt();
//        build();
//        for (int i = 0; i < m; i++) {
//            op = scan.nextInt();
//            x = scan.nextInt();
//            y = scan.nextInt();
//            if(op == 1) {
//                // 是否是一个集合
//                if(isSameSet(x, y)) {
//                    System.out.println("Yes");
//                }else {
//                    System.out.println("No");
//                }
//            }else if (op == 2){
//                // 合并操作
//                union(x, y);
//            }
//        }

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            build();
            in.nextToken();
            int m = (int) in.nval;
            for (int i = 0; i < m; i++) {
                in.nextToken();
                int op = (int) in.nval;
                in.nextToken();
                int x = (int) in.nval;
                in.nextToken();
                int y = (int) in.nval;
                if (op == 1) {
                    out.println(isSameSet(x, y) ? "Yes" : "No");
                } else {
                    union(x, y);
                }
            }
        }
        out.flush();
        out.close();
        br.close();
    }

    private static void union(int i, int j) {
        // 找出两共同的父节点
        int fatheri = find(i);
        int fatherj = find(j);
        if(fatherj == fatheri) {
            return;
        }
        if(sizes[fatheri] >= sizes[fatherj]) {
            sizes[fatheri] += sizes[fatherj];
            father[fatherj] = fatheri;
        } else {
            sizes[fatherj] += sizes[fatheri];
            father[fatheri] = fatherj;
        }
    }

    private static boolean isSameSet(int i, int j) {
        // 找出两个的父节点，看看是否相等
        return find(i) == find(j);
    }

    private static int find(int i) {
        int size = 0;
        // 寻找的时候可以做扁平化
        while(father[i] != i) {
            stack[size ++] = i;
            i = father[i];
        }

        // 扁平化
        while(size > 0) {
            father[stack[--size]] = i;
        }
        return i;
    }

    private static void build() {
        for (int i = 1; i <= n; i++) {
            father[i] = i;
            sizes[i] = 1;
        }
    }


}
